<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>jQuery UI Datepicker - Default functionality</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/cupertino/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
</script>
</head>
<body>
<p>Date: <input type="text" id="datepicker" /></p>
<?php
// Connecting, selecting database
$link = mysql_connect('localhost', 'root', 'ubuntu')
    or die('Could not connect: ' . mysql_error());
echo 'Connected successfully<br>';
mysql_select_db('testing') or die('Could not select database');

$now = time();

echo "Time is: " . $now . "<br>";

$date = date('Y-m-d H:i:s', $now);

echo "Date: " . $date . "<br>";

$date2 = date('d/m/Y', $now);

echo "Date 2: " . $date2 . "<br>";

$array = explode('/', $date2);

$temp = $array[0];

$array[0] = $array[2];

$array[2] = $temp;

$date2 = implode('-', $array);

echo "Date 2: " . $date2 . "<br>";

$query = 'DELETE FROM test';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

// Performing SQL query
$query = 'INSERT INTO test VALUES("ciao","' . $date . '","' . $date . '")';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

// Performing SQL query
$query = 'INSERT INTO test VALUES("ciao","' . $date2 . '","' . $date2 . '")';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

// Performing SQL query
$query = 'INSERT INTO test VALUES("",FROM_UNIXTIME(' . $now . '),FROM_UNIXTIME(' . $now . '))';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

// Performing SQL query
$query = 'SELECT * FROM test';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

// Printing results in HTML
echo "Dates<br>";
echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "\t<tr>\n";
    foreach ($line as $col_value) {
        echo "\t\t<td>$col_value</td>\n";
    }
    echo "\t</tr>\n";
}
echo "</table>\n";

// Performing SQL query
$query = 'SELECT stringvalue, UNIX_TIMESTAMP(date1), UNIX_TIMESTAMP(date2) FROM test';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

// Printing results in HTML
echo "Timestamps<br>";
echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "\t<tr>\n";
    foreach ($line as $col_value) {
        echo "\t\t<td>$col_value</td>\n";
    }
    echo "\t</tr>\n";
}
echo "</table>\n";

// Performing SQL query
$query = 'SELECT stringvalue FROM test';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());

// Printing results in HTML
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
foreach ($line as $col_value) {
   if ($col_value) {
	echo "Stringa non vuota: " . $col_value . "<br>";
	} else {
	echo "Stringa vuota<br>";
	}
	}
}
// Free resultset
mysql_free_result($result);

// Closing connection
mysql_close($link);
?>
</body>
</html>
